<?php
namespace app\admin\model;

use think\Config;
use think\Model;
use think\Db;
use think\Session;

class WithdrawalModel extends Model
{
	/**
	*	会员提现列表
	*/
	public function getdrawals($data)
	{
		$where = [];

		/* 会员姓名 */
		$u_name = empty($data['u_name']) ? '' : $data['u_name'];
		$u_name = trim($u_name);
		if(!empty($u_name)){
			$where['u.u_name'] = $u_name;
		}

		/* 收款人姓名 */
		$w_name = empty($data['w_name']) ? '' : $data['w_name'];
		$w_name = trim($w_name);
		if(!empty($w_name)){
			$where['w.w_name'] = $w_name;
		}

		/* 收款人手机号码 */
		$w_tel = empty($data['w_tel']) ? '' : $data['w_tel'];
		$w_tel = trim($w_tel);
		if(!empty($w_tel)){
			$where['w.w_tel'] = $w_tel;
		}

		/* 收款人账号 */
		$w_account = empty($data['w_account']) ? '' : $data['w_account'];
		$w_account = trim($w_account);
		if(!empty($w_account)){
			$where['w.w_account'] = $w_account;
		}

		/* 提现状态 */
		$w_status = empty($data['w_status']) ? '' : $data['w_status'];
		$w_status = trim($w_status);
		if(!empty($w_status)){
			$where['w.w_status'] = $w_status;
		}

		$join = [
			['sz_user u','w.uid=u.id','left']
		];

		$result = Db::table('sz_withdrawal')->alias('w')
				->join($join)
				->field('w.*,u.u_name')
				->where($where)
				->order('w.id ASC')
				->paginate(20,false,['query' => request()->param()]);

		return $result;

	}

	/**
	*	添加会员提现信息
	*/
	public function addDrawal($data)
	{
		$data['w_time'] = empty($data['w_time']) ? 0 : strtotime(trim($data['w_time']));
		$data['addtime'] = empty($data['addtime']) ? 0 : strtotime(trim($data['addtime']));

		$result = Db::table('sz_withdrawal')->insert($data);

		return $result;
	}

	/**
	*	获取单个提现信息
	*/
	public function getOne($id)
	{
		$join = [
			['sz_user u','w.uid=u.id','left'],
		];

		$result = Db::table('sz_withdrawal')->alias('w')
				->join($join)
				->field('w.*,u.u_name')
				->where('w.id',$id)
				->find();

		return $result;
	}

	/**
	*	修改单个提现信息
	*/
	public function editDrawal($id,$data)
	{
		$data['w_time'] = empty($data['w_time']) ? 0 : strtotime(trim($data['w_time']));
		$result = Db::table('sz_withdrawal')->where('id',$id)->update($data);

		return $result;
	}

	/**
	*	修改单个提现信息
	*/
	public function deleteDrawal($id)
	{

		$result = Db::table('sz_withdrawal')->where('id',$id)->delete();
		if($result){
			return $result;
		}else{
			return false;
		}
		
	}
}
	